package com.example.pongv1;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.Sprite;
import org.andengine.extension.physics.box2d.FixedStepPhysicsWorld;
import org.andengine.extension.physics.box2d.PhysicsConnector;
import org.andengine.extension.physics.box2d.PhysicsFactory;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.input.touch.TouchEvent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.example.pongv1.RessourcesManager;
import com.example.pongv1.PongScene;

public class Joueur implements Constantes{
	final Sprite platform ;
	private LEVEL JLevel;
	private String name;
	private int id;
	private int score;
	private Body jpaddle;
	private static final FixtureDef PADDLE_FIXTUREDEF = PhysicsFactory.createFixtureDef(1, 1, 0);
	
	public Sprite get_raquette(){
		return platform;
	
	}
	public LEVEL get_level(){
		return JLevel;
	}
	public String get_name()
	{
		return name;
	}
	public int get_ID()
	{
		return id;
	}
	public void set_ID(int Identifiant)
	{
		id=Identifiant;
	}
	public int get_score()
	{
		return score;
	}
	public void set_score(int Score)
	{
		score =Score;
	}
	public void set_name(String nom)
	{
	name=nom;
	}
	
	public void set_level(LEVEL level)
	{
		JLevel=level;
	}
	
	public Body get_paddle()
	{
		return jpaddle;
	}

	public Joueur(PongScene PGS, int side){
		if(side==0){
			platform = new Sprite(-CAMERA_WIDTH/2+CAMERA_WIDTH/50-PGS.ressourcesManager.platform1_region.getWidth(), 0,PGS.ressourcesManager.platform1_region,PGS.ressourcesManager.vbom );
		}
		else
		{
			platform = new Sprite(CAMERA_WIDTH/2-CAMERA_WIDTH/50-PGS.ressourcesManager.platform1_region.getWidth(), 0,PGS.ressourcesManager.platform1_region,PGS.ressourcesManager.vbom );
			
		}
	set_level(PGS.ressourcesManager.IAlevel);
	name ="PlayerX";
	id=0;
	score=0;
	createPhysics(PGS.physicsWorld,side);
	}
	public Joueur(PongScene PGS,int side,LEVEL level,String nom){
		if(side==0){
			platform = new Sprite(-CAMERA_WIDTH/2+CAMERA_WIDTH/50-PGS.ressourcesManager.platform1_region.getWidth(), 0,PGS.ressourcesManager.platform1_region,PGS.ressourcesManager.vbom );
		}
		else
		{
			platform = new Sprite(CAMERA_WIDTH/2-CAMERA_WIDTH/50-PGS.ressourcesManager.platform1_region.getWidth(), 0,PGS.ressourcesManager.platform1_region,PGS.ressourcesManager.vbom );
			
		}
		set_level(level);
		set_name(nom);
		set_ID(0);
		set_score(0);
		
		createPhysics(PGS.physicsWorld,side);
		
		}
	
	private void createPhysics(PhysicsWorld physicsWorld, int side)
	{	
		if(side==0)
		{
				//Paddle
				jpaddle = PhysicsFactory.createBoxBody(physicsWorld,-CAMERA_WIDTH/2+CAMERA_WIDTH/50,0,RAQU_WIDTH,RAQU_HEIGH,BodyType.KinematicBody, PADDLE_FIXTUREDEF);
		}
		else
		{
			jpaddle = PhysicsFactory.createBoxBody(physicsWorld,CAMERA_WIDTH/2-CAMERA_WIDTH/50,0,RAQU_WIDTH,RAQU_HEIGH,BodyType.KinematicBody, PADDLE_FIXTUREDEF);
		}
				
		physicsWorld.registerPhysicsConnector(new PhysicsConnector(platform, jpaddle, true, true));
		
		
	}
	public void deplacement(TouchEvent pSceneTouchEvent)
	{
		if(pSceneTouchEvent.getY()/32>=CAMERA_WIDTH)
		{
		
		}
		else
		{
		jpaddle.setTransform((-CAMERA_WIDTH/2+CAMERA_WIDTH/50-RAQU_WIDTH)/32, pSceneTouchEvent.getY()/32, 0);
		}

	}
	
}
